package com.zhiwang.xiaoqu.widget.bottomline

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.zhiwang.xiaoqu.R

class BottomLineFrameLayout : FrameLayout {

    var lineWidth: Float = 1f

    val paint = Paint(Paint.ANTI_ALIAS_FLAG)

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {

        val typedArray = context?.obtainStyledAttributes(attrs, R.styleable.BottomLineFrameLayout)

        lineWidth = typedArray?.getDimension(R.styleable.BottomLineFrameLayout_bfl_line_thickness, 1f) ?: 1f
        val transparent = ContextCompat.getColor(getContext(), android.R.color.transparent)
        paint.color = typedArray?.getColor(
            R.styleable.BottomLineFrameLayout_bfl_line_color,
            transparent
        ) ?: transparent
        typedArray?.recycle()

    }

    override fun dispatchDraw(canvas: Canvas?) {
        canvas?.drawLine(
            0f, measuredHeight - lineWidth / 2f, measuredWidth.toFloat(), measuredHeight - lineWidth / 2f
            , paint
        )
        super.dispatchDraw(canvas)
    }
}